#!/bin/bash

echo "$ZOO_MY_ID" > /data/myid

if [ -e /conf/zoo.cfg ]; then
  \cp /conf/zoo.cfg /zookeeper/conf/
fi

if [ -n "$SERVICE_1" ]; then
    if [ `grep -c "server.1" /zookeeper/conf/zoo.cfg` -eq '0' ]; then
        echo "server.1=$SERVICE_1" >> /zookeeper/conf/zoo.cfg
    fi

fi

if [ -n "$SERVICE_2" ]; then
    if [ `grep -c "server.2" /zookeeper/conf/zoo.cfg` -eq '0' ]; then
        echo "server.2=$SERVICE_2" >> /zookeeper/conf/zoo.cfg
    fi
fi

if [ -n "$SERVICE_3" ]; then
    if [ `grep -c "server.3" /zookeeper/conf/zoo.cfg` -eq '0' ]; then
        echo "server.3=$SERVICE_3" >> /zookeeper/conf/zoo.cfg
    fi
fi

if [ -n "$SERVICE_4" ]; then
    if [ `grep -c "server.4" /zookeeper/conf/zoo.cfg` -eq '0' ]; then
        echo "server.4=$SERVICE_4" >> /zookeeper/conf/zoo.cfg
    fi
fi

if [ -n "$SERVICE_5" ]; then
    if [ `grep -c "server.5" /zookeeper/conf/zoo.cfg` -eq '0' ]; then
        echo "server.5=$SERVICE_5" >> /zookeeper/conf/zoo.cfg
    fi
fi

if [ -n "$SERVICE_6" ]; then
    if [ `grep -c "server.6" /zookeeper/conf/zoo.cfg` -eq '0' ]; then
        echo "server.6=$SERVICE_6" >> /zookeeper/conf/zoo.cfg
    fi
fi

if [ -n "$SERVICE_7" ]; then
    if [ `grep -c "server.7" /zookeeper/conf/zoo.cfg` -eq '0' ]; then
        echo "server.7=$SERVICE_7" >> /zookeeper/conf/zoo.cfg
    fi
fi



/zookeeper/bin/zkServer.sh start-foreground
